<?php
session_start();
ob_start();
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="../public/css/Style.css">
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <title>Nguyễn Đức Thọ</title>
    <div id="head">

    </div>
</head>
<body id="bang">

    <?php
    if (isset($_GET["logout"]) && $_GET["logout"] == true) {
        unset($_SESSION["id"]);
        header("location:login.php");
    }
    ?>




    <div id="menu">

        <ul id="a">
            <li><a href="#">HOME </a></li>
            <li><a href="#">ABOUT</a></li>
            <li><a href="#">FORUMS</a></li>
            <li><a href="#">CONTACT</a></li>
            <li><a href='http://localhost:82/ndtho-web2/public/login.php/'>LOGIN</a>
                <?php if (isset($_SESSION['id'])): ?>
                    <a href="index.php?logout=true"><h3>Logout</h3></a>
                <?php endif; ?>
        </ul>
    </div></br>
    <div id="ten">

        <h2> <p>Việc Làm</p></h2>
    </div>

    <div class="ajax_show"></div>



    <div class="xuong"></div></br>

    <?php
    require_once '../model/db.php';
    require_once '../model/works.php';
    require_once '../model/pagination.php';
    $works = new works();
    $paginations = new Pagination();
    ?>
    <?php
    if (!isset($_GET["page"]))
        $page = 1;
    else
        $page = $_GET["page"];
    $list_of_works = $works->select($page);
    $total = $works->count();
    echo $paginations->Display($page, $total, null, "index.php");
    ?>
    <br>

    <div class="table">
        <table border="1px">
            <tr>
                <td>stt </td>
                <td>images </td>
                <td>noi dung </td>
                <td>Link</td>
                <td>Edit</td>
            </tr>
            <?php foreach ($list_of_works as $list1): ?>
                <tr>
                    <td><?php echo $list1["id"]; ?></td>
                    <td><img src="<?php echo $list1["image"]; ?>" width="100"></td>
                    <td><?php echo $list1["name"]; ?></td>

                    <td><a href='<?php echo $list1["url"]; ?>'><?php echo $list1["url"]; ?></td>
                    <?php if (isset($_SESSION['id']) && $_SESSION['id'] == 1) : ?>
                        <td><a href="edit.php?id=<?php echo $list1["id"]; ?>">  Edit  </a> <br>
                            <a href="#" class="ajax_view" id_keyword="<?php echo $list1["id"]; ?>">  View  </a><br>
                            <a href="#">  Delete </a>
                        </td>
                    <?php else: ?>
                        <td>
                            <a href="#" class="ajax_view" id_keyword="<?php echo $list1["id"]; ?>">  view  </a><br>
                        </td>
                    </tr>
                <?php endif; ?>
            <?php endforeach; ?>
        </table>
    </div>
    <br>
    <script type="text/javascript">
        $(document).ready(function() {
            $(".ajax_view").click(function() {
                id_keyword = $(this).attr('id_keyword');
                url = 'ajax.php?id_keyword=' + id_keyword;
                $.ajax({
                    url: url,
                }).done(function(data) {
                    $('.ajax_show').html(data);
                });
            });
        });
    </script>
</body>
</html>